//
//  UserDefaultsTool.m
//  谭伟
//
//  Created by 谭伟 on 2017/1/15.
//  Copyright © 2017年 谭伟. All rights reserved.
//

#import "UserDefaultsTool.h"

@implementation UserDefaultsTool

+ (void)saveBool:(BOOL)boolean forKey:(NSString *)key
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:boolean forKey:key];
    [defaults synchronize];
    
}
+ (BOOL)boolForKey:(NSString *)key
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    return [defaults boolForKey:key];
    
}

+(void)saveObject:(id)object forKey:(NSString *)key
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:object forKey:key];
    [defaults synchronize];
}

+(id)objectForKey:(NSString *)key
{
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    return [defaults objectForKey:key];
    
}

+ (void)removeForKey:(NSString *)key {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults removeObjectForKey:key];
    [defaults synchronize];
}

+ (void)removeAllKey {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
    NSDictionary *allDefaults = [defaults dictionaryRepresentation];
    
    for (NSString *key in allDefaults) {
        [defaults removeObjectForKey:key];
        [defaults synchronize];
    }
}

@end
